package com.hui.service;

import com.hui.entity.Goods;
import com.hui.mapper.GoodsMapper;
import com.hui.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 李昭辉
 * @Date: 2021/09/17/8:12
 * @Description:
 */
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public Goods getGoodsById(Integer id) {
        return goodsMapper.selectById(id);
    }

    @Override
    public Integer updateGoods(Goods goods) {
        int i = goodsMapper.updateById(goods);
        return i;
    }

    @Override
    public Integer deleteById(Integer id) {
        return goodsMapper.deleteById(id);
    }

    @Override
    public Map<String, Object> getGoodsByCondition(GoodsVo goodsVo) {
        Map<String, Object> map = new HashMap<>();
        // 统计总行数
        Integer integer = goodsMapper.selectCount(null);
        // 分页 ,默认显示第一页，10 条数据
        goodsVo.setOffset((goodsVo.getPageNo() - 1) * goodsVo.getPageSize());
        List<Goods> goodsList = goodsMapper.getGoodsByCondition(goodsVo);
        // 封装数据
        map.put("total", integer);
        map.put("list", goodsList);
        return map;
    }
}
